package com.kun.companion.core.persistence.strategy;

import com.fasterxml.jackson.core.type.TypeReference;
import com.kun.companion.core.util.JacksonUtil;

/**
 * TODO
 *
 * @author gzc
 * @since 2025/2/2 4:50
 **/
public class JsonSerializationStrategy<D> implements SerializationStrategy<D> {
    @Override
    public String getFileTypeName() {
        return "json";
    }

    @Override
    public String serialize(D data) {
        return JacksonUtil.toJsonStr(data);
    }

    @Override
    public D deserialize(String dataStr) {
        return JacksonUtil.parseObject(dataStr, new TypeReference<D>() {
        });
    }
}
